<template>
  <div>
    <div>
      <FormPanel
        ref="formPanel"
        :list="formList"
        :cols="3"
        :formType="type"
        labelWidth="120"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
      />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <multiuse-button v-if="type !== 'show'" :click="saveDialog" type="primary">保 存</multiuse-button>
    </div>

    <Drawer
      :visible.sync="visible"
      :title="dialogTitle"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <SearchName :type="handleType" :rowData="formData" @close="closeHandler" />
    </Drawer>
  </div>
</template>

<script>
import { selectPriceById, insertCustomerPrice, quotationModification, selectDirectivePrice } from '@/api/potenCus/customer/quotedprice';
import { dictionary } from '@/utils/dictMixin';
import { getAllModal, getAllModal1 } from '@/api/potenCus/customer/approval';
import SearchName from './searchName';
import { formatdate } from '@/utils/index';

export default {
  name: 'quotedpriceModal',
  mixins: [dictionary],
  components: {
    SearchName
  },
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.saveData = null;
    this.calcData = null;
    return {
      formList: this.createFormList(),
      handleType: '',
      formData: {},
      visible: false,
      dialogTitle: '',
      conf: { search: '线索选择' },
      purchaseMode: 14261002, // 购置方式
      potentialCustomersId: '', // 潜客id
      newtime: '', // 新增时间戳
      allPrice: 0, //合计价格
      editInit: false, //编辑首次加载
      productId:0
    };
  },
  created() {
    this.init();
    this.getModalList();
  },
  methods: {
    async init() {
      console.log('rowData111111', this.type, this.rowData);
      if (this.type === 'edit' || this.type === 'show') {
        // 更新接口需要的记录 ID
        this.priceId = this.rowData.priceId;
        let res = await selectPriceById({ priceId: this.rowData.priceId });
        if (res.resultCode === 200) {
          this.editInit = true;
          if (res.data.colorId) {
            res.data.carType = `${res.data.brandId},${res.data.seriesId},${res.data.modelId},${res.data.packageId},${res.data.optionId},${res.data.colorId}`;
          }
          console.log(res.data);
          let newtime = new Date(Number(res.data.createdAt));
          res.data.createdAt = formatdate(newtime);
          this.formList.forEach(x => {
            x.initialValue = res.data[x.fieldName];
            if (x.fieldName === 'loanRate' && !res.data[x.fieldName]) {
              x.initialValue = 0;
            }
          });
          this.formList.find(item => item.fieldName === 'discountPrice').max = res.data.salesGuidancePrice;
          this.formList.find(item => item.fieldName === 'potentialCustomerNo').initialValue = this.rowData.potentialCustomerNo;
          let arr = [];
          if (res.data.priceUrl1) {
            arr.push(res.data.priceUrl1);
          }
          if (res.data.priceUrl2) {
            arr.push(res.data.priceUrl2);
          }
          if (res.data.priceUrl3) {
            arr.push(res.data.priceUrl3);
          }
          if (res.data.priceUrl4) {
            arr.push(res.data.priceUrl4);
          }
          this.formList.find(item => item.fieldName === 'caseUrl').initialValue = arr;
          this.saveData = res.data;
          this.calcData = res.data;
          this.amountAmount();
          this.setPurchaseMode(res.data.purchaseMode);
          this.$nextTick(() => {
            this.formList.find(item => item.fieldName === 'nakedCarPrice').initialValue = res.data.nakedCarPrice;
            this.formList.find(item => item.fieldName === 'totalPrice').initialValue = res.data.totalPrice;
          });
        }
      } else if (this.type === 'add') {
        let newtime = new Date();
        this.newtime = newtime.getTime();
        this.formList.find(item => item.fieldName === 'createdAt').initialValue = formatdate(newtime);
        if (this.rowData && this.rowData.potentialCustomersId) {
          // this.potentialCustomersId = this.rowData.potentialCustomersId;
          this.potentialCustomersId = this.rowData.customerBusinessId;
          this.formList.find(item => item.fieldName === 'potentialCustomerNo').initialValue = this.rowData.potentialCustomerNo;
          this.formList.find(item => item.fieldName === 'customerName').initialValue = this.rowData.customerName;
          this.formList.find(item => item.fieldName === 'gender').initialValue = this.rowData.gender;
          this.formList.find(item => item.fieldName === 'intentLevel').initialValue = this.rowData.intentLevel;
          this.formList.find(item => item.fieldName === 'mobilePhone').initialValue = this.rowData.mobilePhone;
          // this.formList.forEach(x => {
          //   x.initialValue = this.rowData[x.fieldName];
          // });
          this.formList.find(item => item.fieldName === 'potentialCustomerNo').disabled = true;
        }
        this.setPurchaseMode(14261002);
      }
    },
    createFormList() {
      const validatePhone = (rule, value, callback) => {
        if (_.isEmpty(value)) {
          callback(new Error('请输入正确的手机号'));
        } else {
          callback();
        }
      };
      return [
        {
          type: 'DATE',
          dateType: 'datetime',
          label: '报价时间',
          disabled: true,
          fieldName: 'createdAt',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '客户编号',
          disabled: this.type === 'add' ? false : true,
          fieldName: 'potentialCustomerNo',
          // placeholder: '请输入...',
          readonly: true,
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.openDriveCancel}></el-button>;
          },
          rules: [{ required: true, message: '请输入客户编号', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '客户名称',
          disabled: true,
          fieldName: 'customerName',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '性别',
          disabled: true,
          fieldName: 'gender',
          placeholder: '请选择',
          initialValue: 10021001,
          itemList: this.createDictList('1002')
          // rules: [{ required: true, message: '请选择性别', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '意向级别',
          disabled: true,
          fieldName: 'intentLevel',
          placeholder: '请选择',
          itemList: this.createDictList('1519')
          // rules: [{ required: true, message: '意向级别不能为空', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '手机号码',
          disabled: true,
          fieldName: 'mobilePhone',
          placeholder: '请输入...'
          // rules: [
          // { required: true, trigger: 'blur', validator: validatePhone },
          // { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
          // { pattern: /^1[3456789]\d{9}$/, message: '手机号码有误', trigger: 'blur' }]
        },
        {
          type: 'INPUT_CASCADER',
          label: '购买车型',
          selfCols: 3,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'carType',
          placeholder: '请选择',
          rules: [{ required: true, message: '请选择购买车型', trigger: 'change' }],
          options: { titles: ['品牌', '车系', '车型', '配置', '选装','产品'] },
          initialValue: '',
          itemList: [],
          change: (val, ref, item) => {
            console.log(item, '产品配置item');
            if (this.type !== 'show') {
              this.setPrice(val, item);
            }
          }
        },
        {
          type: 'BREAK_SPACE',
          label: ''
        },
        {
          type: 'INPUT_NUMBER',
          label: '指导价（元）',
          step: 0.01,
          disabled: true,
          fieldName: 'salesGuidancePrice',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          label: '裸车价（元）',
          step: 0.01,
          min: 0,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'nakedCarPrice',
          placeholder: '请输入...',
          change: val => {
            this.setdownPaymentsMax(val);
            this.formChangeHandleOne('nakedCarPrice', val);
          },
          rules: [{ required: true, message: '请输入裸车价', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '优惠金额（元）',
          step: 0.01,
          min: -99999999,
          max: 99999999,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'discountPrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('discountPrice', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '购车税（元）',
          step: 0.01,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'purchaseTax',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('purchaseTax', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '保险费（元）',
          step: 0.01,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'insurancePremiumPrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('insurancePremiumPrice', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '上牌费（元）',
          step: 0.01,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'licensingFeePrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('licensingFeePrice', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '精品装潢（元）',
          step: 0.01,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'fineDecorationPrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('fineDecorationPrice', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '其他相关费用（元）',
          step: 0.01,
          disabled: this.type === 'show' ? true : false,
          fieldName: 'otherPrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('otherPrice', val);
          }
        },
        {
          type: 'SELECT',
          label: '购置方式',
          // disabled: true,
          fieldName: 'purchaseMode',
          placeholder: '请选择',
          initialValue: 14261002,
          itemList: this.createDictList('1426'),
          change: val => {
            this.setPurchaseMode(val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '金融产品费（元）',
          disabled: true,
          // hidden: false,
          fieldName: 'financeProductPrice',
          placeholder: '请输入...',
          change: val => {
            this.formChangeHandleOne('financeProductPrice', val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '首付金额（元）',
          disabled: true,
          // hidden: false,
          fieldName: 'downPayments',
          placeholder: '请输入...',
          initialValue: 0,
          min: 0,
          max: 99999999,
          change: val => {
            this.setmonthlySupply('downPayments', val);
          },
          rules: [{ required: true, message: '请输入首付金额', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '贷款额（元）',
          disabled: true,
          // hidden: false,
          fieldName: 'loanAmountPrice',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          label: '分期期数',
          step: 1,
          disabled: true,
          // hidden: false,
          fieldName: 'monthlyNumber',
          initialValue: 6,
          min: 1,
          max: 999,
          placeholder: '请输入...',
          change: val => {
            this.setmonthlySupply('monthlyNumber', val);
          },
          rules: [{ required: true, message: '请输入分期期数', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '贷款利率（%）',
          step: 0.01,
          min: 0,
          max: 999.99,
          disabled: this.type === 'show' ? true : false,
          // hidden: false,
          fieldName: 'loanRate',
          initialValue: 0,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入贷款利率', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '每期还款金额（元）',
          // disabled: true,
          // hidden: false,
          fieldName: 'monthlySupply',
          placeholder: '请输入...',
          min: 0,
          max: 99999999,
          change: val => {
            this.setAllPrice(val);
          },
          rules: [{ required: true, message: '请输入每期还款金额', trigger: 'blur' }]
        },
        {
          type: 'BREAK_SPACE',
          label: ''
        },
        {
          type: 'INPUT',
          label: '合计（元）',
          disabled: true,
          fieldName: 'totalPrice',
          selfCols: 1.5,
          placeholder: '请输入...',
          initialValue: '',
          unitRender: () => {
            return <span> 全款金额：{this.allPrice}</span>;
          }
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'remark',
          selfCols: 2,
          placeholder: '请输入...',
          maxlength: 128
        },
        {
          type: 'UPLOAD_IMG',
          selfCols: 3,
          label: '上传报价单',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'caseUrl',
          placeholder: '上传报价单',
          initialValue: [],
          // rules: [{ required: true, message: '上传报价单', trigger: 'change' }],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [7, 6],
            limit: 4,
            isCalcHeight: true
          }
        }
      ];
    },
    setdownPaymentsMax(val) {
      this.formList.find(item => item.fieldName === 'downPayments').max = val;
      let downPayments = this.formList.find(item => item.fieldName === 'downPayments').initialValue;
      if (downPayments > val) {
        this.formList.find(item => item.fieldName === 'downPayments').initialValue = val;
      }
      // this.amountAmount()
    },
    formChangeHandle(val) {
      console.log(val);
      if (val.caseUrl.length === 4) {
        val.caseUrl.map((x, i) => {
          val[`priceUrl${i + 1}`] = x;
        });
      } else if (val.caseUrl.length === 3) {
        val.caseUrl.map((x, i) => {
          val[`priceUrl${i + 1}`] = x;
        });
        val.priceUrl4 = null;
      } else if (val.caseUrl.length === 2) {
        val.caseUrl.map((x, i) => {
          val[`priceUrl${i + 1}`] = x;
        });
        val.priceUrl3 = val.priceUrl4 = null;
      } else if (val.caseUrl.length === 1) {
        val.caseUrl.map((x, i) => {
          val[`priceUrl${i + 1}`] = x;
        });
        val.priceUrl2 = val.priceUrl3 = val.priceUrl4 = null;
      } else {
        val.priceUrl1 = val.priceUrl2 = val.priceUrl3 = val.priceUrl4 = null;
      }
      this.saveData = { ...this.saveData, ...val };
      this.calcData = { ...this.saveData, ...val };
    },
    formChangeHandleOne(type, val) {
      if (this.calcData === null) {
        this.calcData = {};
      }
      if (type === 'discountPrice') {
        let salesGuidancePrice = this.formList.find(item => item.fieldName === 'salesGuidancePrice').initialValue;
        this.formList.find(item => item.fieldName === 'nakedCarPrice').initialValue = salesGuidancePrice - val;
        this.calcData.nakedCarPrice = salesGuidancePrice - val;
        this.setdownPaymentsMax(salesGuidancePrice - val);
      } else if (type === 'nakedCarPrice') {
        let salesGuidancePrice = this.formList.find(item => item.fieldName === 'salesGuidancePrice').initialValue;
        this.formList.find(item => item.fieldName === 'discountPrice').initialValue = salesGuidancePrice - val;
        this.calcData.discountPrice = salesGuidancePrice - val;
      }
      this.calcData[type] = val;
      this.amountAmount();
    },
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        let res = {};
        let cars = this.saveData.carType ? this.saveData.carType.split(',') : [];
        console.log(cars, this.saveData);
        if (!cars[4]) {
          this.$message.info('请完整选择购买车型');
        } else {
          this.saveData.brandId = cars[0] || null;
          this.saveData.seriesId = cars[1] || null;
          this.saveData.modelId = cars[2] || null;
          this.saveData.packageId = cars[3] || null;
           this.saveData.optionId = cars[4] || null; 
          this.saveData.colorId = cars[5] || null;
           this.saveData.productId = this.productId || null;
          if (this.type === 'add') {
            this.saveData.potentialCustomersId = this.potentialCustomersId;
            this.saveData.createdAt = this.newtime;
            res = await insertCustomerPrice({ ...this.saveData, priceMode: 22501002 });
          }
          if (this.type === 'edit') {
            // console.log(this.saveData)
            res = await quotationModification({ ...this.saveData, createdAt: new Date(this.saveData.createdAt).getTime(), priceId: this.priceId });
          }
          if (res.resultCode === 200) {
            this.$message.success('保存成功!');
            this.closeDialog('refresh');
          }
        }
      }
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    // 车型
    async getModalList() {
      // const res = await getAllModal({ type: 0, level: 5, isUnlimited: 10041002 });
      // CMS 更改购买车型-颜色为产品-START
      const res = await getAllModal1({ type: 0, level: 6, isUnlimited: 10041002 });
      // CMS 更改购买车型-颜色为产品-END
      // console.log('车型信息', res)
      if (res.resultCode === 200) {
        console.log('rr',res.data);
        this.formList.find(item => item.fieldName === 'carType').itemList = res.data;
      }
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    openDriveCancel() {
      this.handleType = 'search';
      this.visible = true;
      this.showHandler();
    },
    closeHandler(type, data) {
      this.visible = type;
      if (data) {
        this.formList.find(item => item.fieldName === 'potentialCustomerNo').initialValue = data.potentialCustomerNo;
        this.formList.find(item => item.fieldName === 'customerName').initialValue = data.potentialCustomerName;
        this.formList.find(item => item.fieldName === 'gender').initialValue = data.gender;
        this.formList.find(item => item.fieldName === 'intentLevel').initialValue = data.intent;
        this.formList.find(item => item.fieldName === 'mobilePhone').initialValue = data.mobile;
        this.potentialCustomersId = data.customerBusinessId;
      }
    },
    amountAmount() {
      //计算价格
      let totalPrice = 0;
      let nakedCarPrice = parseFloat(this.calcData.nakedCarPrice) || 0,
        purchaseTax = parseFloat(this.calcData.purchaseTax) || 0,
        insurancePremiumPrice = parseFloat(this.calcData.insurancePremiumPrice) || 0,
        licensingFeePrice = parseFloat(this.calcData.licensingFeePrice) || 0,
        fineDecorationPrice = parseFloat(this.calcData.fineDecorationPrice) || 0,
        otherPrice = parseFloat(this.calcData.otherPrice) || 0;
      totalPrice = nakedCarPrice + purchaseTax + insurancePremiumPrice + licensingFeePrice + fineDecorationPrice + otherPrice;

      this.allPrice = totalPrice.toFixed(2);
      if (this.purchaseMode == 14261002) {
        let financeProductPrice = parseFloat(this.calcData.financeProductPrice) || 0;
        totalPrice += financeProductPrice;
      }
      this.formList.find(item => item.fieldName === 'totalPrice').initialValue = totalPrice.toFixed(2);
      this.setmonthlySupply('nakedCarPrice', nakedCarPrice.toFixed(2));
      console.log(this.formList.find(item => item.fieldName === 'totalPrice').initialValue);
    },
    setPurchaseMode(val) {
      this.purchaseMode = val;
      if (val && val != 14261001) {
        // this.formList = this.createFormList()
        if (this.type !== 'show') {
          this.formList.find(item => item.fieldName === 'financeProductPrice').disabled = false;
          this.formList.find(item => item.fieldName === 'downPayments').disabled = false;
          this.formList.find(item => item.fieldName === 'monthlyNumber').disabled = false;
          this.formList.find(item => item.fieldName === 'monthlyNumber').initialValue = 6;
        }

        this.formList.find(item => item.fieldName === 'financeProductPrice').hidden = false;
        this.formList.find(item => item.fieldName === 'downPayments').hidden = false;
        this.formList.find(item => item.fieldName === 'loanAmountPrice').hidden = false;
        this.formList.find(item => item.fieldName === 'monthlyNumber').hidden = false;
        this.formList.find(item => item.fieldName === 'loanRate').hidden = false;
        this.formList.find(item => item.fieldName === 'monthlySupply').hidden = false;
      } else {
        // this.formList = this.createFormList2()
        this.formList.find(item => item.fieldName === 'financeProductPrice').hidden = true;
        this.formList.find(item => item.fieldName === 'downPayments').hidden = true;
        this.formList.find(item => item.fieldName === 'loanAmountPrice').hidden = true;
        this.formList.find(item => item.fieldName === 'monthlyNumber').hidden = true;
        this.formList.find(item => item.fieldName === 'loanRate').hidden = true;
        this.formList.find(item => item.fieldName === 'monthlySupply').hidden = true;

        this.formList.find(item => item.fieldName === 'downPayments').disabled = true;
        this.formList.find(item => item.fieldName === 'monthlyNumber').disabled = true;
        this.formList.find(item => item.fieldName === 'downPayments').initialValue = '';
        this.formList.find(item => item.fieldName === 'monthlySupply').initialValue = '';
        this.formList.find(item => item.fieldName === 'monthlyNumber').initialValue = '';
      }
    },
    // 根据月数显示月供
    setmonthlySupply(index, val) {
      if (this.type === 'show') {
        return;
      }
      const nakedCarPrice = this.formList.find(item => item.fieldName === 'nakedCarPrice').initialValue; //指导价
      const downPayments = this.formList.find(item => item.fieldName === 'downPayments').initialValue; //首付
      const monthlyNumber = this.formList.find(item => item.fieldName === 'monthlyNumber').initialValue; //期数
      let monthlySupply = 0,
        loanAmountPrice = 0;
      // console.log(index,val,all,downPayments,monthlyNumber)
      switch (index) {
        case 'nakedCarPrice':
          if (val && downPayments && monthlyNumber) {
            let price = (val - downPayments) / monthlyNumber;
            monthlySupply = price.toFixed(2);
            loanAmountPrice = val - downPayments;
          } else if (!val) {
            this.formList.find(item => item.fieldName === 'downPayments').initialValue = '';
            this.formList.find(item => item.fieldName === 'monthlySupply').initialValue = '';
            this.formList.find(item => item.fieldName === 'monthlyNumber').initialValue = '';
          }
          break;
        case 'downPayments': //首付
          if (val && nakedCarPrice && monthlyNumber) {
            let price = (nakedCarPrice - val) / monthlyNumber;
            monthlySupply = price.toFixed(2);
          }
          loanAmountPrice = nakedCarPrice - val;
          break;
        case 'monthlyNumber': //期数
          if (val && nakedCarPrice && downPayments) {
            let price = (nakedCarPrice - downPayments) / val;
            monthlySupply = price.toFixed(2);
            loanAmountPrice = nakedCarPrice - downPayments;
          } else if (!val) {
            this.formList.find(item => item.fieldName === 'monthlySupply').initialValue = '';
          }
          break;
        default:
          break;
      }
      this.formList.find(item => item.fieldName === 'loanAmountPrice').initialValue = loanAmountPrice.toFixed(2);
      // this.formList.find(item=>item.fieldName==='monthlySupply').max = loanAmountPrice
      this.formList.find(item => item.fieldName === 'monthlySupply').initialValue = monthlySupply;
    },
    //根据月供计算合计
    setAllPrice(val) {
      if (!val) {
        val = 0;
      }
      //计算价格
      let totalPrice = 0;
      let purchaseTax = parseFloat(this.calcData.purchaseTax) || 0,
        insurancePremiumPrice = parseFloat(this.calcData.insurancePremiumPrice) || 0,
        licensingFeePrice = parseFloat(this.calcData.licensingFeePrice) || 0,
        fineDecorationPrice = parseFloat(this.calcData.fineDecorationPrice) || 0,
        otherPrice = parseFloat(this.calcData.otherPrice) || 0;
      const downPayments = this.formList.find(item => item.fieldName === 'downPayments').initialValue || 0; //首付
      const monthlyNumber = this.formList.find(item => item.fieldName === 'monthlyNumber').initialValue; //期数
      totalPrice = downPayments + monthlyNumber * val + purchaseTax + insurancePremiumPrice + licensingFeePrice + fineDecorationPrice + otherPrice;

      if (this.purchaseMode == 14261002) {
        let financeProductPrice = parseFloat(this.calcData.financeProductPrice) || 0;
        totalPrice += financeProductPrice;
      }
      this.formList.find(item => item.fieldName === 'totalPrice').initialValue = totalPrice.toFixed(2);
    },
    async setPrice(val, carNameItem) {
      // console.log(val)
      if (!val) {
        return;
      }
      console.log('val',val);
       console.log('val',carNameItem);
      let cars = val ? val.split(',') : [];
      if (cars.length === 6) {
        let productId = '';
        carNameItem.forEach(x => {
          if (x.value == cars[5]) {
            productId = x.productId;
             this.productId = x.productId;
          }
        });
        let data = {
          brandId: cars[0],
          seriesId: cars[1],
          modelId: cars[2],
          packageId: cars[3],
          // color: cars[4],
          productId: productId
        };
       
        const res = await selectDirectivePrice(data);
        // console.log('车型信息', res)
        if (res.resultCode === 200 && res.data && !this.editInit) {
          let directivePrice = res.data.directivePrice;
          this.formList.find(item => item.fieldName === 'salesGuidancePrice').initialValue = directivePrice;
          this.formList.find(item => item.fieldName === 'nakedCarPrice').initialValue = directivePrice;
          this.formList.find(item => item.fieldName === 'discountPrice').initialValue = 0;
          this.formList.find(item => item.fieldName === 'discountPrice').max = directivePrice;
          this.setmonthlySupply('nakedCarPrice', directivePrice.toFixed(2));
          this.setdownPaymentsMax(directivePrice);
          this.formChangeHandleOne('nakedCarPrice', directivePrice);
        } else {
          this.editInit = false;
        }
      }
    }
  }
};
</script>

<style lang="less" scoped>
</style>
